import re

def stringify(dict_:dict):
    d = {}
    for key, value in dict_.items():
        if not re.search("'(\w+(\.<?\w+>?)+|function)'", str(type(value))):
            if type(value) is dict:
                value = stringify(value)
            d[key] = value
        else:
            d[key] = str(value)

    return d


def get_devices(device=''):
    import torch
    if device:
        return str(device)

    devices = ['CPU']

    for device_id in range(torch.cuda.device_count()):
        available_memory, _ = torch.cuda.mem_get_info(device_id)
        if available_memory / 2 ** 30 > 1:
            devices.append(f'GPU:{device_id}')

    return devices
